package com.bobo.controller.back.admin;

import com.bobo.annotations.RequestMapping;
import com.bobo.annotations.RequestMethod;
import com.bobo.controller.base.BaseServlet;
import com.bobo.model.Admin;
import com.bobo.service.admin.AdminServiceImpl;
import com.bobo.service.admin.IAdminService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by anting on 16/11/6.
 */

@WebServlet(name = "BaseServlet", urlPatterns = {"/back/*"})
public class Back extends BaseServlet{


    private IAdminService adminService = new AdminServiceImpl();

    @RequestMapping("/login")
    public String login() {
        return "jsp/back/login";
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String login(HttpServletRequest request) {
        String name = request.getParameter("name");
        String pwd = request.getParameter("pwd");
        Admin admin = adminService.adminCompare(name, pwd);
        if (admin == null) {
            return "fail";
        } else {
            if (admin.getName().equals(name)) {
                request.getSession().setAttribute("admin", admin);
                return "redirect:/admin/back";
            }

        }
        return "fail";
    }
}
